import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

import { viteStaticCopy } from "vite-plugin-static-copy";
const BaseSeverUrl = 'https://xiongan.servicetrial.com'
export default defineConfig({
  define: {
    CESIUM_BASE_URL: JSON.stringify("/cesiumStatic"),
  },
  resolve: {
    alias: {
      '@': './src',
    },
  },
  optimizeDeps: {
    exclude: ['@ffmpeg/ffmpeg', '@ffmpeg/util']
  },
  plugins: [
    vue(),
    viteStaticCopy({
      targets: [
        {
          src: "node_modules/cesium/Build/Cesium/ThirdParty",
          dest: "cesiumStatic",
        },
        {
          src: "node_modules/cesium/Build/Cesium/Workers",
          dest: "cesiumStatic",
        },
        {
          src: "node_modules/cesium/Build/Cesium/Assets",
          dest: "cesiumStatic",
        },
        {
          src: "node_modules/cesium/Build/Cesium/Widgets",
          dest: "cesiumStatic",
        },
      ],
    }),
  ],
  // 配置 MIME 类型 确保 FLV 文件 Content-Type 
  server: {
    proxy: {
      '/api-video': {
        target: BaseSeverUrl,
        changeOrigin: true,
        logLevel: 'debug',
        rewrite: (path) => path.replace(/^\/api-video/, '/api-video/'),
        configure: (proxy, options) => {
          proxy.on('proxyReq', (proxyReq) => {
            console.log(`代理转发地址: ${options.target}${proxyReq.path}`)
          })
        }
      }
    }
  }
});